package com.ruoyi.web.controller.shelves;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.shelves.domain.Hj;
import com.ruoyi.shelves.service.IHjService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * 货架Controller
 *
 * @author tongshuai
 * @date 2021-12-02
 */
@RestController
@RequestMapping("/huojia/hj")
public class HjController extends BaseController
{
    @Autowired
    private IHjService hjService;

    /**
     * 查询货架列表
     */
    @PreAuthorize("@ss.hasPermi('huojia:hj:list')")
    @GetMapping("/list")
    public TableDataInfo list(Hj hj)
    {
        startPage();
        List<Hj> list = hjService.selectHjList(hj);
        return getDataTable(list);
    }

    /**
     * 导出货架列表
     */
    @PreAuthorize("@ss.hasPermi('huojia:hj:export')")
    @Log(title = "货架", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Hj hj)
    {
        List<Hj> list = hjService.selectHjList(hj);
        ExcelUtil<Hj> util = new ExcelUtil<Hj>(Hj.class);
        util.exportExcel(response, list, "货架数据");
    }

    /**
     * 获取货架详细信息
     */
    @PreAuthorize("@ss.hasPermi('huojia:hj:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(hjService.selectHjById(id));
    }

    /**
     * 新增货架
     */
    @PreAuthorize("@ss.hasPermi('huojia:hj:add')")
    @Log(title = "货架", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Hj hj)
    {
        return toAjax(hjService.insertHj(hj));
    }

    /**
     * 修改货架
     */
    @PreAuthorize("@ss.hasPermi('huojia:hj:edit')")
    @Log(title = "货架", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Hj hj)
    {
        return toAjax(hjService.updateHj(hj));
    }

    /**
     * 删除货架
     */
    @PreAuthorize("@ss.hasPermi('huojia:hj:remove')")
    @Log(title = "货架", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(hjService.deleteHjByIds(ids));
    }
}
